#include "queue.h"
//创建
int que_creat(que_head **qh){
	*qh=malloc(sizeof(que_head));
	if(*qh==NULL){
	printf("malloc err\n");
	return -1;
	}
	(*qh)->head=malloc(sizeof(node_t));
	(*qh)->head->next=NULL;
	(*qh)->trail=(*qh)->head;
	puts("创建成功");
	return 0;
}

//入队
int que_insert(que_head *qh,struct Env date){
	//判断是否存在
	int ret=que_exit(qh);
	if(ret!=0){
		printf("no exit\n");
		return ret;
	}
	node_t *node;
	node=malloc(sizeof(node_t));
	if(node==NULL){
	puts("malloc err\n");
	return -1;
	}
	node->data.head[0]=date.head[0];
	node->data.head[1]=date.head[1];
	node->data.head[2]=date.head[2];
	node->data.type=date.type;
	node->data.snum=date.snum;
	node->data.temp[0]=date.temp[0];
	node->data.temp[1]=date.temp[1];
	node->data.hum[0]=date.hum[0];
	node->data.hum[1]=date.hum[1];
	node->data.x=date.x;
	node->data.y=date.y;
	node->data.z=date.z;
	node->data.ill=date.ill;
	node->data.bet=date.bet;
	node->data.adc=date.adc;
	node->next=qh->trail->next;
	qh->trail->next=node;
	qh->trail= node;
	printf("%d,%d\n",node->data.type,node->data.snum);
	puts("入对成功");
}
int que_exit(que_head *qh){
return (qh==NULL?-1:0);
}
//出队
int que_read(que_head *qh,struct Env *date){
	//判断是否为空
	int ret;
	ret=que_empty(qh);
	if(ret!=0){
		printf("empty\n");
		return ret;
	}
	date->head[0]=qh->head->next->data.head[0];
	date->head[1]=qh->head->next->data.head[1];
	date->head[2]=qh->head->next->data.head[2];
	date->type=qh->head->next->data.type;
	date->snum=qh->head->next->data.snum;
	date->temp[0]=qh->head->next->data.temp[0];
	date->temp[1]=qh->head->next->data.temp[1];
	date->hum[0]=qh->head->next->data.hum[0];
	date->hum[1]=qh->head->next->data.hum[1];
	date->x=qh->head->next->data.y;
	date->y=qh->head->next->data.x;
	date->z=qh->head->next->data.z;
	date->ill=qh->head->next->data.ill;
	date->bet=qh->head->next->data.bet;
	date->adc=qh->head->next->data.adc;
	node_t *node;
	node=qh->head->next;
	qh->head->next=node->next;
	free(node);
	puts("出对成功");
	return 0;
}

int que_empty(que_head *qh){
	int ret;
	ret=que_exit(qh);
	if(ret!=0){
		printf("no exit\n");
		return ret;
	}
	return (qh->head==qh->trail?-1:0);

}
//销毁
int que_destroy(que_head **qh){
	int ret=que_exit(*qh);
	if(ret!=0){
		printf("not exit\n");
		return 0;
	}
	node_t *temp=(*qh)->head;
	while((*qh)->head){
		(*qh)->head=(*qh)->head->next;
		free(temp);
		temp=(*qh)->head;
	}
	free(*qh);
	qh=NULL;
	puts("销毁成功");
	return 0;
}

